package com.god530.l01array;

public class ClassDataApp {

	private Person[] a;    // regerence to array
	private int nElems;    // number of data items
	
	//-----------------------------------------
	public ClassDataApp(int max) {
		a = new Person[max]; // create the array
		nElems = 0;          // no items yet
	}
	
	//------------------------------------------
	public Person find(String searchName) { // find specified value
		int j;
		for (j = 0; j < nElems; j++) {
			if (a[j].getLast().equals(searchName)) {
				break;
			}
		}
		if (j == nElems) {
			return null;
		} else {
			return a[j];
		} // end find()
	}
	
	//pub person into array
	public void insert(String last, String first, int age) {
		a[nElems] = new Person(last, first, age);
		nElems++;                                 // increment size
	}
	
	//----------------------------------------------------
	public boolean delete(String searchNames) { // delete person from array
		int j;
		for (j = 0; j < nElems; j++) { // look for it
			if (a[j].getLast().equals(searchNames)) {
				break;
			}
		}
		if(j == nElems)
			return false;
		else {
			for (int k = j; k < nElems; k++) {
				a[k] = a[k+1];
			}
			nElems--;
			return true;
		}
	} // end delete()
	
	//-------------------------------------------------
	public void displayA() {  // display array contants
		for (int j = 0; j < nElems; j++) { // for each element
			a[j].displayPerson();    // display it
		}
	}
	
	//-------------------------------------------------
	
	
	public static void main(String[] args) {
		// TODO Auto-generated method stub

	}

}
